//
//  ViewController.m
//  ControlFun
//
//  Created by student on 16/2/18.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//触摸背景的时候，关闭键盘
- (IBAction)backTap:(id)sender
{
    [self.nameTextField resignFirstResponder];
    [self.phoneTextField resignFirstResponder];
}

//分段控件改变触发的方法
- (IBAction)segementChanged:(UISegmentedControl *)sender
{
    if (sender.selectedSegmentIndex == 0)
    {
        //1 如果是点开关段
        //显示开关 隐藏按钮
        //2 如果是点按钮段
        //相反
        self.leftSwitch.hidden = NO;
        self.rightSwitch.hidden = NO;
        self.doSomethingBtn.hidden = YES;
    }
    else
    {
        self.leftSwitch.hidden = YES;
        self.rightSwitch.hidden = YES;
        self.doSomethingBtn.hidden = NO;
    }
    
}
//开关触发处理方法
- (IBAction)switchChanged:(UISwitch *)sender
{
    //开关的当前开关状态 on属性
    BOOL open = sender.on;
    //设置状态 并是否要带上动画
    [self.leftSwitch setOn:open animated:YES];
    [self.rightSwitch setOn:open animated:NO];
}
//doSomething按钮的方法
- (IBAction)doSomethingBthPressed:(id)sender
{
    
}
//滑动条滑动 触发的方法
- (IBAction)sliderChanged:(UISlider *)sender
{
    //滑动条的值 value属性
    int value = sender.value;
    //把滑动条的值显示到Label上
    self.sliderValueLabel.text = [NSString stringWithFormat:@"%i",value];
    

}

// 练习:
// 1. 编写doSomething按钮的事件处理方法
//    1.1 点击按钮弹出操作表,见图10501B.png
- (IBAction)dosomethingPressed:(UIButton *)sender
{
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"你确定么？" delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"是的，我确定！" otherButtonTitles:@"取消", nil];
    [sheet showInView:self.view];
}
//    1.2 编写提示框的代理方法,如果点的是"是的,我确定"项,则弹出消息框,见10501C.png
#pragma mark - 弹出提示框(UIAlertView)
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == actionSheet.destructiveButtonIndex){

    // 1. 弹出简单提示框
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"某些事项被执行了"  // 标题
                                                        message:@"放轻松了，一切都正常运行了"  // 信息
                                                       delegate:self         // 代理人(即哪个对象来处理这个UIAlertView对象的事件)
                                              cancelButtonTitle:@"耶！！！"       // 按钮上的文字
                                              otherButtonTitles:nil];        // 更多按钮
    [alertView show];
    }
}




// 2. 纯代码方式实现本程序
//纯代码方式修改view为UIControl类对象 见给出的例子












@end
